package com.ifengxue.ioc.util;

import javax.annotation.Nullable;
import java.lang.reflect.Method;

/**
 * 方法工具
 * @author LiuKeFeng
 * @date 2017-08-11
 */
public class MethodUtil {
    private static final Class<?>[] EMPTY_CLASS_ARRAY = {};

    /**
     * 从目标类中寻找指定的方法
     * @param name
     * @param target
     * @return
     */
    @Nullable
    public static Method findNullableMethod(String name, Class<?> target) {
        return findNullableMethod(name, target, EMPTY_CLASS_ARRAY);
    }

    @Nullable
    public static Method findNullableMethod(String name, Class<?> target, Class<?>... parameterTypes) {
        try {
            return target.getMethod(name, parameterTypes);
        } catch (NoSuchMethodException e) {
            return null;
        }
    }
}
